﻿using System;

namespace SCSInternetBanking.LibertyReserve
{
    public static class HistorySample
    {
        private static readonly ApiCredentials g_credentials = new ApiCredentials()
        {
            AccountNumber = "U1234567",
            ApiName = "ApiName",
            SecurityWord = "SecurityWord",
        };

        static void Main(string[] args)
        {
            IApiAgent agent = ApiAgentFactory.Create(ApiProtocol.Xml, g_credentials);
            agent.RequireValidSslCertificate = true;

            try
            {
                int pageIndex = 0;
                HistoryResult result;

                Console.WriteLine("Transaction list:");
                Console.WriteLine("   Batch    Time        From -> To          Amount / Fee      Balance Currency");
                do
                {
                    result = agent.History(new HistorySpecification()
                    {
                        From = DateTime.Parse("2011-01-01"),
                        Till = DateTime.Parse("2012-01-01"),
                    }, pageIndex++ , 20);
                
                    foreach (HistoryItem item in result.Items)
                    {
                        Console.WriteLine(item.ToString());
                    }
                } 
                while (result.HasMore);
            }
            catch (ApiException ex)
            {
                Console.Error.WriteLine(ex);
            }
        }
    }
}
